home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.11 Nov 90 / FKEY Source Code / Simple Shell test / compare sort times.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-03  |  1.2 KB  |  53 lines  |  [TEXT/KAHL]

  1. /* 
  2.  
  3.     To compare sorting times enable the code generation options profile.
  4.     Add the profile library to the project and run as usual. 
  5.     
  6.     Comparing the sorting time of each method to selection sort time we 
  7.     get the following results.
  8.     
  9.                 Sort Method        % Change
  10.                 ===========        =========
  11.                 Selection        0%
  12.                 Shell            -53.13%
  13.                 Bubble            +126.24%
  14.     
  15.     What this means is, it takes the shell sort 53.13% less time to sort
  16.     the same data as it does the selection sort.  The bubble sort takes
  17.     126.24% more time.
  18.     
  19.     The reason for comparing the sorting times of the shell sort to the 
  20.     selection sort is the shell sort reduces to the selection sort when
  21.     H is 1.
  22.     
  23. */
  24.  
  25.  
  26. main()
  27.     {
  28.     char    *elem, *el;
  29.     int        num;
  30.     
  31.     elem = "fdacbegzjmoqpzweyNQIOnπQiqyudgkeakcxhgasgshASjchAShKJWSKHGS°∏";
  32.     
  33.     num = strlen( elem );
  34.     el = NewPtr((long)num+1);
  35.     BlockMove(elem,el,(long)num+1);
  36.         
  37.     printf("BUBBL  Before: %s\n",el);
  38.     bubble(el,num);
  39.     printf("BUBBL  After: %s\n",el);
  40.  
  41.     BlockMove(elem,el,(long)num+1);
  42.     printf("SHELL  Before: %s\n",el);
  43.     shell(el,num);
  44.     printf("SHELL  After: %s\n",el);
  45.  
  46.     BlockMove(elem,el,(long)num+1);
  47.     printf("SELECT Before: %s\n",el);
  48.     Selection(el,num);
  49.     printf("SELECT After: %s\n",el);
  50.  
  51.     }
  52.  
  53.